<template>
	<view>
		<Listscroll requestUrl="/app/app-mine/device-warning" :params="params" requestType="post">
			<template #default="scope">
				<view class="notice-item" v-for="(item,i) in  taskList" :key="i" >
					<view class="notice-item__title" @click="markPointsList(item,i)">
						<view class="title">{{item.name}}</view>
					</view>
					<view class="operation-button">
						<!-- <view class="up-button" @click="editTask"></view> -->
						<view class="edit-button" @click="editTask(item,i)"></view>
						<view class="delete-button" @click="deleteTask(item,i)"></view>
					</view>
			<!-- 		<view class="notice-item__containter" v-if="item.detectionPointList.length >0">{{item.detectionPointList.length}}个标记点</view> -->
				</view>
			</template>
		</Listscroll>
		<view class="operation-button">
			<view class="add-button" @click="addNewTask"></view>
		</view>
	</view>
</template>

<script setup>
import {ref} from "vue"
import Listscroll from "@/components/list-scroll/list-scroll.vue"
import {
	    onLoad,onNavigationBarButtonTap
	  } from "@dcloudio/uni-app";
	import {batchInsertPoint } from '@/api/deviceTest.js';	  
const params = ref({})
const enterPrise = ref("")
const taskList = ref([])
const taskKey = ref('')
// onLoad 接受 跳转过来 页面传递的参数
	  onLoad((option) => {
	   //console.log("optionoption",option.id);
	   //if()
	   enterPrise.value = option.id;
	   taskKey.value = "task" + enterPrise.value;
	   taskList.value = uni.getStorageSync(taskKey.value) || [];
	  });
	 
	  const markPointsList = (item,i) => {
		  console.log("进入标记点列表页",item);
		  let info = {
				index: i,
				taskKey: taskKey.value,
			}
			console.log("iiiiii",info);
		  uni.navigateTo({
		  			   url: '/pages/putOnRecord/detectionPointList?info='+ encodeURIComponent(JSON.stringify(info))
		  			});
	  }
	  const editTask = (item,i) => {
	  		  //console.log("编辑任务",item);
			  //console.log("编辑任务1",i);
			  uni.showModal({
			          title: '请输入任务名',
			          content: item.name,
			          editable:true,//是否显示输入框
			  		placeholderText:'请输入修改的任务名',//输入框提示内容
			          confirmText: '确认',
			          cancelText: '取消',
			          success: (res) => {
			            if (res.confirm) {
			              console.log('输入的内容：', res.content);
						  
			            }
			          } 
			        });
			  
	  }
	  const deleteTask = () => {
	  		  console.log("删除任务");
			  uni.showModal({
			  		title: '有确认取消的弹窗',
			  		content: '确认要删除该项吗？',
			  		success: function(res) {
			  		if (res.confirm) {
			  			console.log('点击了确认');
						console.log("taskList.value",taskList.value);
			  		} else {
			  			console.log('点击了取消')
			  		}
			  	}
			  })

	  }
      const addNewTask = () =>{
		   console.log("新建任务");
		  uni.showModal({
		          title: '请输入任务名',
		          content: '',
		          editable:true,//是否显示输入框
		  		placeholderText:'请输入任务名称',//输入框提示内容
		          confirmText: '确认',
		          cancelText: '取消',
		          success: (res) => {
		            if (res.confirm) {
		              console.log('输入的内容：', res.content);
					   let taskData = {
					  	name:res.content,
					  	detectionPointList:[]
					   }
					  taskList.value.push(taskData);
					  uni.setStorageSync(taskKey.value, taskList.value);
					  console.log("yyyyyy",uni.getStorageSync(taskKey.value));
		            }
		          } 
		        });
	  }
	  onNavigationBarButtonTap(function (e) {
		    let factoryId = uni.getStorageSync('factoryId');
			let groupList = [];
			console.log("ggggg",JSON.parse(JSON.stringify(uni.getStorageSync('task' +factoryId))));
			let tempList = JSON.parse(JSON.stringify(uni.getStorageSync('task' +factoryId)));
			tempList.forEach((item)=>{
				if(item.detectionPointList){
					groupList.concat(item.detectionPointList)
				}
			})
			console.log("grgrgr",groupList);
			let params = {
		  	factoryId:factoryId,
		  	groupList:JSON.stringify(uni.getStorageSync('task' +factoryId))
		    };
			//params = JSON.stringify(params);
			console.log("params",params);
		   batchInsertPoint(params).then(res => {
			  console.log("ressss",res);
			  //上传成功之后，将storage中的task清空
		  })
	  })
</script>

<style lang="scss" scoped>
.notice-item {
	display: flex;
	flex-direction: column;
	background: #fff;
	border-radius: 10rpx;
	margin: 20rpx 30rpx 0 30rpx;
	padding: 20rpx;
	//cursor: pointer;
	position: relative;
}
.notice-item__title {
	display: flex;
	justify-content: space-between;
	margin-bottom: 10rpx;
	.title {
		font-weight: bold;
		font-size: 28rpx;
		color: #455BDF;
		cursor: pointer;
	}
	.type {
		display: inline-block;
		padding: 4rpx 8rpx;
		background: #fef0f0;
		border:2rpx solid #fde2e2;
		color: rgb(251, 69, 59);
		border-radius: 10rpx;
		font-size: 20rpx;
		&.green{
			background: #f0f9eb;
			border-color:#e1f3d8;
			color: #67c23a;
		}
	}
}
.notice-item__containter {
	text-overflow: -o-ellipsis-lastline;
	overflow: hidden;
	text-overflow: ellipsis;
	display: flex;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	font-size: 28rpx;
}
.operation-button{
	position: absolute;
	right:30rpx;
	display: flex;
	flex-direction: row;
	.edit-button{
		width:32rpx;
		height:32rpx;
		background-image:url('@/static/deviceImg/edit-button.png') ;
		background-size: 100% 100%;
		cursor: pointer;
		//width:40rpx;
		// height:30rpx;
		// display: inline-block;
		// padding: 4rpx 8rpx;
		// background: #00aaff;
		// border:2rpx solid #00aaff;
		// color: #ffffff;
		// border-radius: 10rpx;
		// font-size: 20rpx;
		margin-left: 10rpx;
	}
	.delete-button{
		width:32rpx;
		height:32rpx;
		background-image:url('@/static/deviceImg/delete-button.png') ;
		background-size: 100% 100%;
		margin-left: 10rpx;
		cursor: pointer;
		//width:40rpx;delete-button.png
		// height:30rpx;
		// margin-left: 10rpx;
		// display: inline-block;
		// padding: 4rpx 8rpx;
		// background: #fef0f0;
		// border:2rpx solid #fde2e2;
		// color: rgb(251, 69, 59);
		// border-radius: 10rpx;
		// font-size: 20rpx;
	}
	.up-button{
		width:32rpx;
		height:32rpx;
		background-image:url('@/static/deviceImg/up-button.png') ;
		background-size: 100% 100%;
		cursor: pointer;
		// display: inline-block;
		// padding: 4rpx 8rpx;
		// background: #00aaff;
		// border:2rpx solid #00aaff;
		//color: #ffffff;
		// border-radius: 10rpx;
		// font-size: 20rpx;
	}
	.add-button{
		width:48rpx;
		height:48rpx;
		background-image:url('@/static/deviceImg/add-button.png') ;
		background-size: 100% 100%;
		margin-left: 10rpx;
		margin-top: 20rpx;
		cursor: pointer;
	}
}
</style>
